package com.wider.fileTools;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.swing.tree.DefaultMutableTreeNode;

public class fileTools {
	//private static final Boolean False = null;


	public HashMap<Object,Object> getChild(String root){
	/*	String tempPath;
		File rootFile = new File(rootPath);
		File tempFile;
		HashMap<Object, Boolean> fileHash = new HashMap<Object, Boolean>();
		String separator=File.separator;
		for(int loop=0;loop<rootFile.listFiles().length;loop++)
		{
			tempPath=rootPath + separator + rootFile.listFiles()[loop].toString();
			System.out.println(rootFile.listFiles()[loop].toString());
			tempFile=new File(tempPath);
			fileHash.put(rootFile.listFiles()[loop].toString(),tempFile.isDirectory());
		}*/
		 HashMap<Object, Object> params = new HashMap<Object,Object>();
		 String path;
		 int tempi;
		 String separator=File.separator;
		 File now=new File(root);
		 File temp;
		 for(int loop=0;loop<now.listFiles().length;loop++){
			 path=root + separator + now.list()[loop].toString();
			 //System.out.println(path);
			 temp=new File(path);
			 if(temp.isDirectory()){
				 tempi=loop+1;
				 params.put(tempi,now.list()[loop].toString());
			 }
			 else{
				 tempi=(loop+1)*(-1);
				 params.put(tempi,now.list()[loop].toString());
			 }
		 }
		return params;
	}
	
	
	public void addChildren(DefaultMutableTreeNode rootNode,HashMap<Object,Object> fileHash){
		String temp;
		int index;
		DefaultMutableTreeNode node;
		Collection collection = fileHash.keySet();
		Iterator iterator=collection.iterator();
		
		while(iterator.hasNext()){
			index=Integer.parseInt(iterator.next().toString());
			temp=fileHash.get(index).toString();
			node=new DefaultMutableTreeNode(temp);
			rootNode.add(node);
			if(index>0){
				node.add(new DefaultMutableTreeNode("ttt"));
			}
			
		}
		
	}
	
	
}
